from typing import Optional

from sqlalchemy import Integer, BIGINT
from sqlmodel import Field

from src.base.beans import PageParam
from src.base.enums import MenuType
from src.domain.base_model import TenantModel
from src.base.beans import Bigint


class SysMenuBase(TenantModel):
    menu_id: Optional[Bigint] = Field(default=None, primary_key=True, description="菜单序号", sa_type=BIGINT,
                                      sa_column_kwargs={"comment": "菜单序号"})
    parent_id: Optional[Bigint] = Field(default=None, description="父菜单序号", sa_type=BIGINT,
                                        sa_column_kwargs={"comment": "父菜单序号"})
    menu_name: Optional[str] = Field(default=None, description="菜单名称", sa_column_kwargs={"comment": "菜单名称"})
    menu_code: Optional[str] = Field(default=None, description="菜单编码", sa_column_kwargs={"comment": "菜单编码"})
    menu_type: Optional[MenuType] = Field(default=None, description="菜单类型", sa_type=Integer,
                                          sa_column_kwargs={"comment": "菜单类型", "server_default": "0"})
    perm: Optional[str] = Field(default=None, description="权限", sa_column_kwargs={"comment": "权限"})
    path: Optional[str] = Field(default=None, description="路由地址", sa_column_kwargs={"comment": "路由地址"})
    component: Optional[str] = Field(default=None, description="组件路径", sa_column_kwargs={"comment": "组件路径"})
    icon: Optional[str] = Field(default=None, description="图标", sa_column_kwargs={"comment": "图标"})


class SysMenu(SysMenuBase, table=True):
    __tablename__ = "sys_menu"
    __table_args__ = {'extend_existing': True, 'comment': '菜单表'}


class SysMenuReq(SysMenuBase, PageParam):
    create_time_range: Optional[list[str]] = Field(default=None, description="创建时间范围")
    update_time_range: Optional[list[str]] = Field(default=None, description="更新时间范围")


class SysMenuResp(SysMenuBase):
    pass
